<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 </HEAD>
 <style>
.top{
	width:1000px;
	margin:20px auto;
	text-align:center;
}
 .right{
	float:left;
	width:310px;
	height:245px;
	background:gray;
	margin:auto;
 }
 .right span{
	color:red;
 }
 .right .title{
	margin:3px auto;
	width:98%;
	height:35px;
	background:#dddddd;
	text-align:center;
	font-size:20px;
 	color:blue;
 }
 .right .content{
	margin:1px auto;
	width:98%;
	height:200px;
	background:#eeeeee;
	text-align:center;
	font-size:150px
 }
 </style>
 <BODY>
  <div class='top'>
 	<h1>三片计分器</h1>
 </div>
 <div  class='top' style="height:240px;">
  <div class='right' style="margin-left:180px">
  	<div class='title' id='team_a'>A队</div>
  	<div class="content">
  		<span>0</span><br>
  		<input type="text" name="input_a" id='one'>
  	</div>
  </div>
  <div class='right' style="margin-left:10px">
  	<div class='title' id='team_b'>B队</div>
  	<div class="content">
  		<span>0</span><br>
  		<input type="text" name="input_a" id='two'>
  	</div>
  </div>
 </div>
 <div class='top'>
 	<input type='button' id='reset_one' value="开始游戏">
 	<input type='button' id='reset_up' value="返回上一次记录">
 </div>
<table>
	<tr>
		
	</tr>
	<tr></tr>
</table>
 </BODY>
</HTML>
<script src="http://www.ceacbj.com.cn/admin/Public/js/jquery.js"></script>
<script type="text/javascript">
var raw_one = parseInt($('input#one').parents('div').children('span').html())
var raw_two = parseInt($('input#two').parents('div').children('span').html())
var flag = false
$('input#one').blur(function(){
	raw_one = parseInt($('input#one').parents('div').children('span').html())
	raw_two = parseInt($('input#two').parents('div').children('span').html())
	if(!flag){
		if(confirm('冒似你还没有开始游戏,立即开始吗？')){
			startGame()
		}
	}
	if(!parseInt($(this).val()) || (parseInt($(this).val())%5 !=0) || (parseInt($(this).val())>300 &&  parseInt($(this).val()) !=400) || parseInt($(this).val())<0){
		alert('分数输入有误')
	}else{
		if(parseInt($(this).val()) && flag){
			var tol = parseInt(raw_one) + parseInt($(this).val())
			if(parseInt($(this).val()) == 400){
				var two_tol = raw_two;
			}else{
				var two_tol = raw_two + 300 - parseInt($(this).val());
			}
			var int1 = setInterval(function(){
				var raw = $('input#one').parents('div').children('span').html()
				var nums = parseInt(raw)+1
				if(raw == tol){
					window.clearInterval(int1)
				}else{
					$('input#one').parents('div').children('span').html(nums)
				}
			},5)
			var int2 = setInterval(function(){
				var raw_two = $('input#two').parents('div').children('span').html()
				var nums = parseInt(raw_two)+1
				if(raw_two >= two_tol){
					window.clearInterval(int2)
				}else{
					$('input#two').parents('div').children('span').html(nums)
				}
			},5)
			$(this).val('')
		}
	}
})
$('input#two').blur(function(){
	raw_one = parseInt($('input#one').parents('div').children('span').html())
	raw_two = parseInt($('input#two').parents('div').children('span').html())
	if(!flag){
		if(confirm('冒似你还没有开始游戏,立即开始吗？')){
			startGame()
		}
	}
	if(!parseInt($(this).val()) || (parseInt($(this).val())%5 !=0) || (parseInt($(this).val())>300 &&  parseInt($(this).val()) !=400) || parseInt($(this).val())<0){
		alert('分数输入有误')
	}else{
		if(parseInt($(this).val()) && flag){
			var tol = parseInt(raw_two) + parseInt($(this).val())
			if(parseInt($(this).val()) == 400){
				var two_tol = raw_one;
			}else{
				var two_tol = raw_one + 300 - parseInt($(this).val());
			}
			var int1 = setInterval(function(){
				var raw = $('input#two').parents('div').children('span').html()
				var nums = parseInt(raw)+1
				if(raw == tol){
					window.clearInterval(int1)
				}else{
					$('input#two').parents('div').children('span').html(nums)
				}
			},5)
			var int2 = setInterval(function(){
				var raw_two = $('input#one').parents('div').children('span').html()
				var nums = parseInt(raw_two)+1
				if(raw_two >= two_tol){
					window.clearInterval(int2)
				}else{
					$('input#one').parents('div').children('span').html(nums)
				}
			},5)
			$(this).val('')
		}
	}
})
$('input#reset_one').click(function(){
	if(flag){
		if(confirm('确认要清零吗？')){
			$('input#one').parents('div').children('span').html(0)
			$('input#two').parents('div').children('span').html(0)
		}
	}else{
		startGame()
	}
})
function startGame(){
	var ateam = window.prompt('请输入 A 队名称')
	var bteam = window.prompt('请输入 B 队名称')
	$('div#team_a').html(ateam)
	$('div#team_b').html(bteam)
	flag = true
	$(this).val('重新开始')
}
$('input#reset_up').click(function(){
	$('input#one').parents('div').children('span').html(raw_one)
	$('input#two').parents('div').children('span').html(raw_two)
})
</script>
